package base

import (
	"fmt"
	"strings"
)

//写一个程序，统计一个字符串中每个单词出现的次数。比如：”how do you do”中how=1 do=2 you=1。
func Exercise1() {
	str := "how do you do"
	strSlice := strings.Split(str, " ")
	countMap := make(map[string]int, 10)
	for _, value := range strSlice {
		_, ok := countMap[value]
		if ok {
			countMap[value] += 1
		} else {
			countMap[value] = 1
		}
	}
	fmt.Println("how do you do 每个单词出现的次数: ", countMap)
}

//观察下面代码，写出最终的打印结果。
func Exercise2() {
	type Map map[string][]int
	m := make(Map)
	s := []int{1, 2}
	s = append(s, 3, 4)
	fmt.Printf("%+v\n", s)
	m["q1mi"] = s
	s = append(s[:1], s[2:]...)
	fmt.Printf("%+v\n", s)
	fmt.Printf("%+v\n", m["q1mi"])
}
